/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import model.funcionario.Funcionario;
import controller.ControllerFuncionario;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.hibernate.HibernateException;
import model.excecoes.ErroDAOException;
import model.excecoes.ErroNegocioException;

/**
 *
 * @author aluno
 */
public class FormFuncionario extends javax.swing.JFrame {

    /**
     * Creates new form FormFuncionario
     */
    private Funcionario funcionario = null;
    private ControllerFuncionario controlFuncionario = null;
    private int linhaSelecionada = 0;
    private List<Funcionario> funcionarios = null;
    private DefaultTableModel modelo = null;

    public FormFuncionario() {
        initComponents();
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        controlFuncionario = new ControllerFuncionario();
        modelo = new DefaultTableModel();
        modelo.setColumnIdentifiers(new String[]{"Código", "Nome", "Rua", "Cidade", "Bairro", "CEP", "Complemento", "Login", "RG", "CPF", "Salário R$", "Telefone", "Celular", "Função", "E-Mail"});
        jTabelaFuncionario.setModel(modelo);
    }
    
    private void limparCampos(){
        jTNome.setText("");
        jTRua.setText("");
        jTCidade.setText("");
        jTBairro.setText("");
        jFCEP.setText("");
        jTComplemento.setText("");
        jFDataNascimento.setText("");
        jTSalario.setText("");
        jTRG.setText("");
        jTCPF.setText("");
        jFTelefone.setText("");
        jFCelular.setText("");
        
    }

    private void preencher(String operacao) {
        if (operacao.equals("Cadastrar")) {
            funcionario = new Funcionario();
            funcionario.setNome(jTNome.getText());
            funcionario.getEndereco().setRua(jTRua.getText());
            funcionario.getEndereco().setCidade(jTCidade.getText());
            funcionario.getEndereco().setBairro(jTBairro.getText());
            funcionario.getEndereco().setCep(jFCEP.getText());
            funcionario.getEndereco().setComplemento(jTComplemento.getText());
            funcionario.getEndereco().setUf(comboUF.getSelectedItem().toString());
            funcionario.setLogin(jTLogin.getText());
            String senha = new String(jPSenha.getPassword());
            funcionario.setSenha(senha);
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
            try {
                funcionario.setDataNascimento(format.parse(jFDataNascimento.getText()));
                funcionario.setDataAdmissao(format.parse(format.format(new Date())));
            } catch (ParseException ex) {
                Logger.getLogger(FormFuncionario.class.getName()).log(Level.SEVERE, null, ex);
            }
            funcionario.setFuncao(comboFuncao.getSelectedItem().toString());
            funcionario.setSalario(Double.parseDouble(jTSalario.getText()));
            funcionario.setRg(jTRG.getText());
            funcionario.setCpf(jTCPF.getText());
            funcionario.getContato().setTelefone(jFTelefone.getText());
            funcionario.getContato().setCelular(jFCelular.getText());
            funcionario.getContato().setEmail(jTEMail.getText());

        } else {
            if (operacao.equals("Alterar")) {
                linhaSelecionada = jTabelaFuncionario.getSelectedRow();
                jTNome.setText(funcionarios.get(linhaSelecionada).getNome());
                jTRua.setText(funcionarios.get(linhaSelecionada).getEndereco().getRua());
                jTCidade.setText(funcionarios.get(linhaSelecionada).getEndereco().getCidade());
                jTBairro.setText(funcionarios.get(linhaSelecionada).getEndereco().getBairro());
                jFCEP.setText(funcionarios.get(linhaSelecionada).getEndereco().getCep());
                jTComplemento.setText(funcionarios.get(linhaSelecionada).getEndereco().getComplemento());
                DefaultComboBoxModel model = new DefaultComboBoxModel();
                model.addElement(funcionarios.get(linhaSelecionada).getEndereco().getUf());
                comboUF.setModel(model);
                SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
                jTLogin.setText(funcionarios.get(linhaSelecionada).getLogin());
                jPSenha.setText(funcionarios.get(linhaSelecionada).getSenha());
                jFDataNascimento.setText(format.format(funcionarios.get(linhaSelecionada).getDataNascimento()));
                jTSalario.setText(String.valueOf(funcionarios.get(linhaSelecionada).getSalario()));
                DefaultComboBoxModel modelo = new DefaultComboBoxModel();
                modelo.addElement(funcionarios.get(linhaSelecionada).getFuncao());
                comboFuncao.setModel(modelo);
                jTRG.setText(funcionarios.get(linhaSelecionada).getRg());
                jTCPF.setText(funcionarios.get(linhaSelecionada).getCpf());
                jFTelefone.setText(funcionarios.get(linhaSelecionada).getContato().getTelefone());
                jFCelular.setText(funcionarios.get(linhaSelecionada).getContato().getCelular());
                jTEMail.setText(funcionarios.get(linhaSelecionada).getContato().getEmail());

                funcionario = new Funcionario();
                funcionario.setCodigo(funcionarios.get(linhaSelecionada).getCodigo());
                funcionario.setNome(jTNome.getText());
                funcionario.getEndereco().setRua(jTRua.getText());
                funcionario.getEndereco().setCidade(jTCidade.getText());
                funcionario.getEndereco().setBairro(jTBairro.getText());
                funcionario.getEndereco().setCep(jFCEP.getText());
                funcionario.getEndereco().setComplemento(jTComplemento.getText());
                funcionario.getEndereco().setUf(comboUF.getSelectedItem().toString());
                try {
                    funcionario.setDataNascimento(format.parse(jFDataNascimento.getText()));
                } catch (ParseException ex) {
                    Logger.getLogger(FormFuncionario.class.getName()).log(Level.SEVERE, null, ex);
                }
                funcionario.setSalario(Double.parseDouble(jTSalario.getText()));
                funcionario.setRg(jTRG.getText());
                funcionario.setCpf(jTCPF.getText());
                funcionario.setLogin(jTLogin.getText());
                String senha = new String(jPSenha.getPassword());
                funcionario.setSenha(senha);
                funcionario.setFuncao(comboFuncao.getSelectedItem().toString());
                funcionario.getContato().setTelefone(jFTelefone.getText());
                funcionario.getContato().setCelular(jFCelular.getText());
                funcionario.getContato().setEmail(jTEMail.getText());

            } else {
                linhaSelecionada = jTabelaFuncionario.getSelectedRow();
                funcionario = new Funcionario();
                funcionario.setCodigo(funcionarios.get(linhaSelecionada).getCodigo());
            }
        }
    }

    private void listar(String op) {
        try {
            if (op.equals("Todos")) {
                funcionarios = controlFuncionario.listarFuncionario("Todos", "Todos");
            } else {
                if (op.equals("Código")) {
                    funcionarios = controlFuncionario.listarFuncionario(jTConsulta.getText(), op);
                } else {
                    if (op.equals("Nome")) {
                        funcionarios = controlFuncionario.listarFuncionario(jTConsulta.getText(), op);
                    } else {
                        if (op.equals("CPF")) {
                            funcionarios = controlFuncionario.listarFuncionario(jTConsulta.getText(), op);
                        }
                    }
                }
            }

            for (Funcionario f : funcionarios) {
                modelo.addRow(new String[]{String.valueOf(f.getCodigo()), f.getNome(), f.getEndereco().getRua(), f.getEndereco().getCidade(), f.getEndereco().getBairro(), f.getEndereco().getCep(), f.getEndereco().getComplemento(), f.getLogin(), f.getRg(), f.getCpf(), String.valueOf(f.getSalario()), f.getContato().getTelefone(), f.getContato().getCelular(), f.getFuncao(), f.getContato().getEmail()});
            }

            jTabelaFuncionario.setModel(modelo);

        } catch (ErroDAOException ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
        } catch (ErroNegocioException ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTLogin = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPSenha = new javax.swing.JPasswordField();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTRua = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTCidade = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTBairro = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jFCEP = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        jTComplemento = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        comboUF = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jFDataNascimento = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        jTSalario = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        comboFuncao = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jTRG = new javax.swing.JTextField();
        jTCPF = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jFTelefone = new javax.swing.JFormattedTextField();
        jLabel14 = new javax.swing.JLabel();
        jFCelular = new javax.swing.JFormattedTextField();
        jLabel15 = new javax.swing.JLabel();
        jTEMail = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTabelaFuncionario = new javax.swing.JTable();
        jLabel16 = new javax.swing.JLabel();
        jTConsulta = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        comboCampo = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Login do Funcionário"));

        jLabel1.setText("Login");

        jLabel2.setText("Senha");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTLogin)
                    .addComponent(jPSenha, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jPSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados Cadastrais do Funcionário"));

        jLabel3.setText("Nome");

        jLabel4.setText("Rua");

        jLabel5.setText("Cidade");

        jLabel6.setText("Bairro");

        jLabel7.setText("CEP");

        jLabel8.setText("Complemento");

        jLabel9.setText("UF");

        comboUF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acre", "Alagoas", "Amazonas", "Amapá", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará", "Paraná", "Pernambuco", "Piauí", "Rio Grande do Norte", "Rio Grande do Sul", "Rio de Janeiro", "Rondônia", "Roraima", "Santa Catarina", "São Paulo", "Sergipe", "Tocantins" }));

        jLabel10.setText("Data Nasc.");

        jLabel11.setText("Salário R$");

        jLabel12.setText("Função");

        comboFuncao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrador", "Usuário" }));

        jLabel18.setText("RG");

        jLabel19.setText("CPF");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFCEP))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTComplemento))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(comboUF, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comboFuncao, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTSalario))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTRG, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jTRua))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTNome)))
                .addGap(0, 0, 0))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jFCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(comboUF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jFDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(comboFuncao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(jTRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Contato com o Funcionário"));

        jLabel13.setText("Telefone");

        jLabel14.setText("Celular");

        jLabel15.setText("E-Mail");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jFTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 62, Short.MAX_VALUE))
                    .addComponent(jTEMail))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jFCelular, jFTelefone});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jFTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jFCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jTEMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/7893_64x64.png"))); // NOI18N
        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/8448_128x128.png"))); // NOI18N
        jButton2.setText("Alterar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/846_128x128.png"))); // NOI18N
        jButton3.setText("Excluir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTabelaFuncionario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Código", "Nome", "Rua", "Cidade", "Bairro", "CEP", "Complemento", "Login", "RG", "CPF", "Salário R$", "Telefone", "Celular", "Função", "E-Mail"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTabelaFuncionario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabelaFuncionarioMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTabelaFuncionario);

        jLabel16.setText("Consulta");

        jLabel17.setText("Campo");

        comboCampo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "Código", "Nome", "CPF" }));

        jButton4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/7833_64x64.png"))); // NOI18N
        jButton4.setText("Listar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/8443_128x128.png"))); // NOI18N
        jButton5.setText("Fechar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(99, 99, 99)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16)
                            .addComponent(jTConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(comboCampo, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(73, 73, 73)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE)
                        .addComponent(jButton5)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton5)
                        .addGap(46, 46, 46))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton3)
                                .addComponent(jTConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton4))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel17)
                                .addComponent(jLabel16)))
                        .addContainerGap(52, Short.MAX_VALUE))))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (ValidarConteudo.validar(jTNome, "Nome") == false) {
            jTNome.requestFocus();
        } else {
            if (ValidarConteudo.validar(jTRua, "Rua") == false) {
                jTRua.requestFocus();
            } else {
                if (ValidarConteudo.validar(jTCidade, "Cidade") == false) {
                    jTCidade.requestFocus();
                } else {
                    if (ValidarConteudo.validar(jTBairro, "Bairro") == false) {
                        jTBairro.requestFocus();
                    } else {
                        if (ValidarConteudo.validar(jFCEP, "CEP") == false) {
                            jFCEP.requestFocus();
                        } else {
                            if (ValidarConteudo.validar(jTComplemento, "Complemento") == false) {
                                jTComplemento.requestFocus();
                            } else {
                                if (ValidarConteudo.validar(jFDataNascimento, "Data de Nascimento") == false) {
                                    jFDataNascimento.requestFocus();
                                } else {
                                    if (ValidarConteudo.validar(jTSalario, "Salário") == false) {
                                        jTSalario.requestFocus();
                                    } else {
                                        if (ValidarConteudo.validar(jTRG, "RG") == false) {
                                            jTRG.requestFocus();
                                        } else {
                                            if (ValidarConteudo.validar(jTCPF, "CPF") == false) {
                                                jTCPF.requestFocus();
                                            } else {
                                                if (ValidarConteudo.validar(jFTelefone, "Telefone") == false) {
                                                    jFTelefone.requestFocus();
                                                } else {
                                                    if (ValidarConteudo.validar(jFCelular, "Celular") == false) {
                                                        jFCelular.requestFocus();
                                                    } else {
                                                        if (ValidarConteudo.validar(jTEMail, "E-Mail") == false) {
                                                            jTEMail.requestFocus();
                                                        } else {

                                                            try {
                                                                preencher("Cadastrar");
                                                                controlFuncionario.cadastrarFuncionario(funcionario);
                                                                JOptionPane.showMessageDialog(rootPane, "Os dados do funcionário foram cadastrados com sucesso!", "Sucesso!", JOptionPane.INFORMATION_MESSAGE);
                                                                limparCampos();
                                                            } catch (ErroDAOException ex) {
                                                                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
                                                                limparCampos();
                                                            } catch (HibernateException ex) {
                                                                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
                                                                limparCampos();
                                                            } catch (ErroNegocioException ex) {
                                                                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
                                                                limparCampos();
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        linhaSelecionada = jTabelaFuncionario.getSelectedRow();
        if (linhaSelecionada == -1) {
            JOptionPane.showMessageDialog(rootPane, "Para alterar os dados do funcionário,\n tem que primeiro clicar em algum registro exibido na tabela e clique em Alterar.");
        } else {
            try {

                controlFuncionario.alterarFuncionario(funcionario);
                JOptionPane.showMessageDialog(rootPane, "Os dados do funcionário foram alterados com sucesso!", "Sucesso!", JOptionPane.INFORMATION_MESSAGE);
                this.dispose();
            } catch (ErroDAOException ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
            } catch (HibernateException ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
            } catch (ErroNegocioException ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro do sistema!", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTabelaFuncionarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabelaFuncionarioMouseClicked
        // TODO add your handling code here:
        preencher("Alterar");
    }//GEN-LAST:event_jTabelaFuncionarioMouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        linhaSelecionada = jTabelaFuncionario.getSelectedRow();
        if (linhaSelecionada == -1) {
            JOptionPane.showMessageDialog(rootPane, "Para excluir os dados do funcionário,\n tem que primeiro clicar em algum registro exibido na tabela e clique em Alterar.");
        } else {
            Object[] botoes = {"Sim", "Não"};
            int opcao = JOptionPane.showInternalOptionDialog(rootPane, "Deseja realmente excluir o registro?", "Confirma",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, botoes, botoes[0]);

            if (opcao == JOptionPane.YES_OPTION) {
                try {
                    preencher("Excluir");
                    controlFuncionario.excluirFuncionario(funcionario);
                    JOptionPane.showMessageDialog(rootPane, "Os dados do funcionário foram excluídos com sucesso!", "Sucesso!", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (ErroDAOException ex) {
                    JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
                } catch (HibernateException ex) {
                    JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro de Dados do sistema!", JOptionPane.ERROR_MESSAGE);
                } catch (ErroNegocioException ex) {
                    JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Erro do sistema!", JOptionPane.ERROR_MESSAGE);
                }
            }else{
                
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        
        
        listar(comboCampo.getSelectedItem().toString());
    }//GEN-LAST:event_jButton4ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboCampo;
    private javax.swing.JComboBox comboFuncao;
    private javax.swing.JComboBox comboUF;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JFormattedTextField jFCEP;
    private javax.swing.JFormattedTextField jFCelular;
    private javax.swing.JFormattedTextField jFDataNascimento;
    private javax.swing.JFormattedTextField jFTelefone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPasswordField jPSenha;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTBairro;
    private javax.swing.JTextField jTCPF;
    private javax.swing.JTextField jTCidade;
    private javax.swing.JTextField jTComplemento;
    private javax.swing.JTextField jTConsulta;
    private javax.swing.JTextField jTEMail;
    private javax.swing.JTextField jTLogin;
    private javax.swing.JTextField jTNome;
    private javax.swing.JTextField jTRG;
    private javax.swing.JTextField jTRua;
    private javax.swing.JTextField jTSalario;
    private javax.swing.JTable jTabelaFuncionario;
    // End of variables declaration//GEN-END:variables
}
